<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型对象</title>
</head>
<body>
    <h1>原型对象</h1>

    <script>
        // 定义构造函数
        function Dog(name,age) {
            //属性
            this.name = name ;
            this.age = age ;

            //方法
            this.sayHello = function() {
                return '你好，我叫' + this.name + ',今年' + this.age + "岁了" ;
            }
        }


        // 逐个扩展属性
        Dog.prototype.color = '白色' ;
        Dog.prototype.weight = 30 ;

        // 逐个扩展行为
        Dog.prototype.getInfo = function() {
            return '颜色:' + this.color + ',体重:' + this.weight ;
        }

        
        var xh = new Dog('小花',8) ;
        console.log(xh);
        


    </script>
</body>
</html>